usage()
{
   echo "usage: $cmd {--help}"
   echo "       $cmd {-m <\"managed system\"> -p <\"partition name\"> -t <\"partition name\">"
   echo "             -o [m | a | r] -r [cpu | mem | slot] [-q <quantity>]"
   echo "             [-i <drawer MTMS>] [-s <slot number>] -w <timeout>"
   echo "             -d <detail level>}"
   exit $1
}
help()
{
   echo "usage:"
   echo "  --help                - print this message"
   echo "  -m <\"managed system\"> - the machine type and serial number of the"
   echo "                          managed system to execute the dlpar operation."
   echo "                          The name specified must be enclosed in double quotes"
   echo "                          and of the form mmmm*sssss where mmm is the"
   echo "                          model type such as 7040, and ssss is the serial"
   echo "                          number of the managed system."
   echo "  -p <\"partition name\"> - the partition to execute the dlpar operation"
   echo "                          the name specified must be enclosed in double quotes."
   echo "  -t <\"partition name\"> - the target partition to execute the dlpar operation."
   echo "                          the name specified must be enclosed in double quotes."
   echo "                          this argument is only valid for move operation."
   echo "  -o <operation>        - the dlpar operation"
   echo "                          m indicates a move operation"
   echo "                          a indicates an add operation"
   echo "                          r indicates a remove operation"
   echo "  -r <resource type>    - the type of resource"
   echo "                          value can be cpu, mem or slot"
   echo "  -q <quantity>         - the integer quantity that represents the number"
   echo "                          of processors to dynamically reconfigure, or"
   echo "                          number of LMBs if memory. This argument should not"
   echo "                          be specified for slot resources."
   echo "  -i <drawer MTMS>      - the id, e.g, Machine Type and Serial Number"
   echo "                          of an I/O slot's scoping drawer. Should not"
   echo "                          be specified if the resource type is not slot."
   echo "  -s <slot number>      - the slot number of a PCI slot. Only specify"
   echo "                          this argument for slot resource."
   echo "  -w <timeout>          - the elapsed time in minutes after which the"
   echo "                          dlpar operation will be aborted."
   echo "  -d <detail level>     - an integer between 0 and 5 to specify the level"
   echo "                          of detail that should be displayed upon returned"
   echo "                          of the dlpar operation."
   echo "  NOTE: arguments must be passed in the order specified"
   exit 0
}
cmd=`basename $0`
if [ "$1" = "" ]
then
   usage 1
fi

targetPartSpecified="0"
managedSystem=""
sourcePartitionName=""
operation=""
resourceType=""
quantity="-1"
id="-1"
slotNumber="-1"
timeout="0"
detailLevel="0"
#managedSystem="\"$2\""
#sourcePartitionName="\"$4\""
#targetPartitionName="\"$6\""
managedSystem=""
sourcePartitionName=""
targetPartitionName=""
set -- `getopt -u -l help "m:p:t:o:r:q:i:s:w:d:" $*`
while [ "$1" != "--" ]
do
   case $1 in
	"-m")
           managedSystem="$2"
	   shift;
	   shift;
	   ;;
	"-p")
           sourcePartitionName="$2"
	   shift;
	   shift;
	   ;;
	"-t")
	   targetPartSpecified="1"
           targetPartitionName="$2"
	   shift;
	   shift;
	   ;;
	"-o")
	   operation="$2"
	   shift;
	   shift;
	   ;;
	"-r")
	   resourceType="$2"
	   shift;
	   shift;
	   ;;
	"-q")
	   quantity="$2"
	   shift;
	   shift;
	   ;;
	"-i")
	   id="$2"
	   shift;
	   shift;
	   ;;
	"-s")
	   slotNumber="$2"
	   shift;
	   shift;
	   ;;
	"-w")
	   timeout=$2
	   shift;
	   shift;
	   ;;
	"-d")
	   detailLevel=$2
	   shift;
	   shift;
	   ;;
	"--help")
           help
	   ;;
	*)
	   usage 1
	   ;;
     esac
done
if [ "$operation" = "" ]
then
   usage 1
fi
if [ "$operation" = "m" -a "$targetPartSpecified" = "0" ]
then
   usage 1
fi
if [ "$operation" != "m" -a "$targetPartSpecified" = "1" ]
then
   usage 1
fi

newCommand=''

#add manage system to newCommand string
if [ "$managedSystem" != "" ]
then
newCommand=$newCommand" -m "$managedSystem
fi
#add operation to newCommand string
if [ "$operation" != "" ]
then
newCommand=$newCommand" -o "$operation
fi

#add resource type to newCommand string
if [ "$resourceType" != "" ]
then
newCommand=$newCommand" -r "$resourceType
fi

#add source partition to newCommand string
if [ "$sourcePartitionName" != "" ]
then
newCommand=$newCommand" -p "$sourcePartitionName
fi

#add target partition to newCommand string
if [ "$targetPartitionName" != "" ] 
then
newCommand=$newCommand" -t "$targetPartitionName
fi

#add drawer id to newCommand string
if [ "$id" != "-1" ]
then
newCommand=$newCommand" -i "$id
fi

#add slot id to newCommand string
if [ "$slotNumber" != "-1" ]
then
newCommand=$newCommand" -s "$slotNumber
fi

#add quantity to newCommand string
if [ "$quantity" != "-1" ]
then
newCommand=$newCommand" -q "$quantity
fi

#add detail level to newCommand string
if [ "$detailLevel" != "-1" ]
then
newCommand=$newCommand" -d "$detailLevel
fi

#add timeout to newCommand string
if [ "$timeout" != "-1" ]
then
newCommand=$newCommand" -w "$timeout
fi

#call change hardware resource command
chhwres $newCommand

exit $?

